#include "Spl_list.h" 
//尾删
void delete_node_end(Link_list* list)
{
    if (NULL == list)
    {
        printf("没人辣\n");
        return;
    }
    Node *O = list->head;
    if (O->next == NULL)
    {
        printf("只有一个人辣\n");
        free(O);  // 释放头节点的内存
        list->head = NULL;
        return;
    }
      
    while (O->next->next != NULL) 
    {  
        O = O->next;  // 找到倒数第二个一个节点 
    }
    O->next = NULL;
    free(O->next);  // 释放最后一个节点的内存
}

//头删
void delete_node_begin(Link_list ** list)
{
    if (NULL == list)
    {
        printf("没人辣\n");
        return;
    }
    Node *temp = (*list)->head;
    (*list)->head = (*list)->head->next;
    free(temp);
}

//指定位置删除
void delete_node(Link_list* list, int id)
{
    if (NULL == list)
    {
        printf("没人辣\n");
        return;
    }
    Node *O = list->head;
    
    for (int i = 1; i < id-1; i++)
    {
        O = O->next;  // 找到要删除的前一个节点  
    }
    if (O == NULL || O->next == NULL)
        {
            printf("位置不对\n");
            return;
        }

    Node *temp = O->next;
    O->next = O->next->next;  // 断开连接
    temp = NULL ;
    free(temp);
}